/**
 * 
 */
package com.lidian.dateTest;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * @author lidian
 * 
 */
public class DateSort {

	public static void main(String[] args) {

		SimpleDateFormat bartDateFormat = new SimpleDateFormat("MM-dd-yyyy");
		String dateString01 = "2-22-2010";
		String dateString0 = "1-30-2010";
		String dateString1 = "9-29-2009";
		String dateString2 = "9-28-2009";
		String dateString3 = "11-29-2008";
		String dateString4 = "9-11-2008";
		String dateString5 = "9-30-2009";
		List<Date> dateList = new ArrayList<Date>();

		try {

			Date date01 = bartDateFormat.parse(dateString01);
			Date date0 = bartDateFormat.parse(dateString0);
			Date date1 = bartDateFormat.parse(dateString1);
			Date date2 = bartDateFormat.parse(dateString2);
			Date date3 = bartDateFormat.parse(dateString3);
			Date date4 = bartDateFormat.parse(dateString4);
			Date date5 = bartDateFormat.parse(dateString5);
			dateList.add(date01);
			dateList.add(date0);
			dateList.add(date1);
			dateList.add(date2);
			dateList.add(date3);
			dateList.add(date4);
			dateList.add(date5);

		}

		catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
		Comparator<Date> c = new Comparator<Date>() {

			public int compare(Date o1, Date o2) {
				Date c1 = (Date) o1;
				Date c2 = (Date) o2;
				return c1.compareTo(c2);
			}

		};
		Collections.sort(dateList, c);
		List<List<Date>> list = new ArrayList<List<Date>>();
		List<Date> dl1 = new ArrayList<Date>();
		Date d1 = dateList.remove(0);
		dl1.add(d1);
		for (Date date : dateList) {
			if (d1.getYear() == date.getYear()) {
				dl1.add(date);
			} else {
				list.add(dl1);
				dl1 = new ArrayList<Date>();
				dl1.add(date);
				d1 = date;
			}
		}
		list.add(dl1);

		System.out.println();
	}
}
